package com.lanou.service.impl;

import com.lanou.bean.CrmRefer;
import com.lanou.bean.Staff;
import com.lanou.mapper.CrmReferMapper;
import com.lanou.service.ReferService;
import com.lanou.utils.AjaxResult;
import com.lanou.utils.DateTimeUtil;
import com.lanou.utils.ValidateUtil;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by dllo on 18/4/16.
 */
@Service
public class ReferServiceImpl implements ReferService {
    @Resource
    private CrmReferMapper crmReferMapper;

    @Override
    public AjaxResult insertStuInfo(@Param(value = "name") String name,
                                    @Param(value = "telephone") String telephone,
                                    @Param(value = "qq") String qq,
                                    @Param(value = "intentionLevel") String intentionLevel,
                                    @Param(value = "courseTypeId") String courseTypeId,
                                    @Param(value = "classId") String classId,
                                    @Param(value = "source") String source,
                                    @Param(value = "remark") String remark) {
        if (!ValidateUtil.validateQq(qq)){
            return AjaxResult.getNO("请输入正确的qq号");
        }else if (!ValidateUtil.validateMobile(telephone)){
            return AjaxResult.getNO("请输入正确的手机号");
        }else {

            CrmRefer crmRefer = new CrmRefer();
            crmRefer.setReferid("213132");
            crmRefer.setName(name);
            crmRefer.setTelephone(telephone);
            crmRefer.setQq(qq);
            crmRefer.setIntentionlevel(intentionLevel);
            crmRefer.setCoursetypeid(courseTypeId);
            crmRefer.setClassid(classId);
            crmRefer.setSource(source);
            crmRefer.setRemark(remark);
            Subject subject = SecurityUtils.getSubject();
            Staff staff = (Staff) subject.getPrincipal();
            String staffid = staff.getStaffId();
            crmRefer.setStaffid(staffid);

            crmRefer.setCreatedate(DateTimeUtil.getSystemTimeUtil());
            int flag = crmReferMapper.insert(crmRefer);
            System.out.println("保存结果: "+crmRefer.toString());
            return AjaxResult.getOK("保存成功");
        }

    }
}
